package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.business.domain.NcGenAccount;
import com.lxmes.business.service.INcGenAccountService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 应收/付账款Controller
 * 
 * @author zhangzhiyu
 * @date 2022-11-25
 */
@RestController
@RequestMapping("/business/account")
public class NcGenAccountController extends BaseController
{
    @Autowired
    private INcGenAccountService ncGenAccountService;

    /**
     * 查询应收/付账款列表
     */
    @PreAuthorize("@ss.hasPermi('business:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcGenAccount ncGenAccount)
    {
        startPage();
        List<NcGenAccount> list = ncGenAccountService.selectNcGenAccountList(ncGenAccount);
        return getDataTable(list);
    }

    /**
     * 导出应收/付账款列表
     */
    @PreAuthorize("@ss.hasPermi('business:account:export')")
    @Log(title = "应收账款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcGenAccount ncGenAccount)
    {
        List<NcGenAccount> list = ncGenAccountService.selectNcGenAccountList(ncGenAccount);
        ExcelUtil<NcGenAccount> util = new ExcelUtil<NcGenAccount>(NcGenAccount.class);
        util.exportExcel(response, list, "应收账款数据");
    }

    /**
     * 获取应收/付账款详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:account:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncGenAccountService.selectNcGenAccountById(id));
    }

    /**
     * 新增应收/付账款
     */
    @PreAuthorize("@ss.hasPermi('business:account:add')")
    @Log(title = "应收/付账款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcGenAccount ncGenAccount)
    {
        return toAjax(ncGenAccountService.insertNcGenAccount(ncGenAccount));
    }

    /**
     * 修改应收/付账款
     */
    @PreAuthorize("@ss.hasPermi('business:account:edit')")
    @Log(title = "应收/付账款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcGenAccount ncGenAccount)
    {
        return toAjax(ncGenAccountService.updateNcGenAccount(ncGenAccount));
    }

    /**
     * 删除应收/付账款
     */
    @PreAuthorize("@ss.hasPermi('business:account:remove')")
    @Log(title = "应收/付账款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncGenAccountService.deleteNcGenAccountByIds(ids));
    }
    /**
     * 开票通知单记账
     */
    @Log(title = "开票通知单记账", businessType = BusinessType.INSERT)
    @GetMapping("/billAddAccount/{ids}")
    public AjaxResult billAddAccount(@PathVariable Long[] ids)
    {
        return toAjax(ncGenAccountService.billAddAccount(ids));
    }
}
